<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CAD_Doc: Actions Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">CAD_Doc<span id="projectnumber">&#160;1.0</span>
   </div>
   <div id="projectbrief">cad synopsis</div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){initNavTree('md__build_2__deps_2googletest-src_2docs_2reference_2actions.html',''); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">Actions Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="autotoc_md243"></a></p>
<p><a href="../gmock_for_dummies.md#actions-what-should-it-do"><b>Actions</b></a> specify what a mock function should do when invoked. This page lists the built-in actions provided by GoogleTest. All actions are defined in the <code>testing</code> namespace.</p>
<h1><a class="anchor" id="autotoc_md244"></a>
Returning a Value</h1>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft"><a class="el" href="class_action.html">Action</a>   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>Return()</code>   </td><td class="markdownTableBodyLeft">Return from a <code>void</code> mock function.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>Return(value)</code>   </td><td class="markdownTableBodyLeft">Return <code>value</code>. If the type of <code>value</code> is different to the mock function's return type, <code>value</code> is converted to the latter type <em>at the time the expectation is set</em>, not when the action is executed.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ReturnArg&lt;N&gt;()</code>   </td><td class="markdownTableBodyLeft">Return the <code>N</code>-th (0-based) argument.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>ReturnNew&lt;T&gt;(a1, ..., ak)</code>   </td><td class="markdownTableBodyLeft">Return <code>new T(a1, ..., ak)</code>; a different object is created each time.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ReturnNull()</code>   </td><td class="markdownTableBodyLeft">Return a null pointer.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>ReturnPointee(ptr)</code>   </td><td class="markdownTableBodyLeft">Return the value pointed to by <code>ptr</code>.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ReturnRef(variable)</code>   </td><td class="markdownTableBodyLeft">Return a reference to <code>variable</code>.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>ReturnRefOfCopy(value)</code>   </td><td class="markdownTableBodyLeft">Return a reference to a copy of <code>value</code>; the copy lives as long as the action.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ReturnRoundRobin({a1, ..., ak})</code>   </td><td class="markdownTableBodyLeft">Each call will return the next <code>ai</code> in the list, starting at the beginning when the end of the list is reached.   </td></tr>
</table>
<h1><a class="anchor" id="autotoc_md245"></a>
Side Effects</h1>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft"><a class="el" href="class_action.html">Action</a>   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>Assign(&amp;variable, value)</code>   </td><td class="markdownTableBodyLeft">Assign <code>value</code> to variable.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>DeleteArg&lt;N&gt;()</code>   </td><td class="markdownTableBodyLeft">Delete the <code>N</code>-th (0-based) argument, which must be a pointer.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>SaveArg&lt;N&gt;(pointer)</code>   </td><td class="markdownTableBodyLeft">Save the <code>N</code>-th (0-based) argument to <code>*pointer</code>.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>SaveArgPointee&lt;N&gt;(pointer)</code>   </td><td class="markdownTableBodyLeft">Save the value pointed to by the <code>N</code>-th (0-based) argument to <code>*pointer</code>.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>SetArgReferee&lt;N&gt;(value)</code>   </td><td class="markdownTableBodyLeft">Assign <code>value</code> to the variable referenced by the <code>N</code>-th (0-based) argument.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>SetArgPointee&lt;N&gt;(value)</code>   </td><td class="markdownTableBodyLeft">Assign <code>value</code> to the variable pointed by the <code>N</code>-th (0-based) argument.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>SetArgumentPointee&lt;N&gt;(value)</code>   </td><td class="markdownTableBodyLeft">Same as <code>SetArgPointee&lt;N&gt;(value)</code>. Deprecated. Will be removed in v1.7.0.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>SetArrayArgument&lt;N&gt;(first, last)</code>   </td><td class="markdownTableBodyLeft">Copies the elements in source range [<code>first</code>, <code>last</code>) to the array pointed to by the <code>N</code>-th (0-based) argument, which can be either a pointer or an iterator. The action does not take ownership of the elements in the source range.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>SetErrnoAndReturn(error, value)</code>   </td><td class="markdownTableBodyLeft">Set <code>errno</code> to <code>error</code> and return <code>value</code>.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>Throw(exception)</code>   </td><td class="markdownTableBodyLeft">Throws the given exception, which can be any copyable value. Available since v1.1.0.   </td></tr>
</table>
<h1><a class="anchor" id="autotoc_md246"></a>
Using a Function, Functor, or Lambda as an Action</h1>
<p>In the following, by "callable" we mean a free function, <code>std::function</code>, functor, or lambda.</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft"><a class="el" href="class_action.html">Action</a>   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>f</code>   </td><td class="markdownTableBodyLeft">Invoke <code>f</code> with the arguments passed to the mock function, where <code>f</code> is a callable.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>Invoke(f)</code>   </td><td class="markdownTableBodyLeft">Invoke <code>f</code> with the arguments passed to the mock function, where <code>f</code> can be a global/static function or a functor.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>Invoke(object_pointer, &amp;class::method)</code>   </td><td class="markdownTableBodyLeft">Invoke the method on the object with the arguments passed to the mock function.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>InvokeWithoutArgs(f)</code>   </td><td class="markdownTableBodyLeft">Invoke <code>f</code>, which can be a global/static function or a functor. <code>f</code> must take no arguments.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>InvokeWithoutArgs(object_pointer, &amp;class::method)</code>   </td><td class="markdownTableBodyLeft">Invoke the method on the object, which takes no arguments.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>InvokeArgument&lt;N&gt;(arg1, arg2, ..., argk)</code>   </td><td class="markdownTableBodyLeft">Invoke the mock function's <code>N</code>-th (0-based) argument, which must be a function or a functor, with the <code>k</code> arguments.   </td></tr>
</table>
<p>The return value of the invoked function is used as the return value of the action.</p>
<p>When defining a callable to be used with <code>Invoke*()</code>, you can declare any unused parameters as <code>Unused</code>:</p>
<div class="fragment"><div class="line"><span class="keyword">using </span>::testing::Invoke;</div>
<div class="line"><span class="keywordtype">double</span> Distance(Unused, <span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y) { <span class="keywordflow">return</span> sqrt(x*x + y*y); }</div>
<div class="line">...</div>
<div class="line">EXPECT_CALL(mock, Foo(<span class="stringliteral">&quot;Hi&quot;</span>, _, _)).WillOnce(Invoke(Distance));</div>
</div><!-- fragment --><p><code>Invoke(callback)</code> and <code>InvokeWithoutArgs(callback)</code> take ownership of <code>callback</code>, which must be permanent. The type of <code>callback</code> must be a base callback type instead of a derived one, e.g.</p>
<div class="fragment"><div class="line">BlockingClosure* done = <span class="keyword">new</span> BlockingClosure;</div>
<div class="line">... Invoke(done) ...;  <span class="comment">// This won&#39;t compile!</span></div>
<div class="line"> </div>
<div class="line">Closure* done2 = <span class="keyword">new</span> BlockingClosure;</div>
<div class="line">... Invoke(done2) ...;  <span class="comment">// This works.</span></div>
</div><!-- fragment --><p>In <code>InvokeArgument&lt;N&gt;(...)</code>, if an argument needs to be passed by reference, wrap it inside <code>std::ref()</code>. For example,</p>
<div class="fragment"><div class="line"><span class="keyword">using </span>::testing::InvokeArgument;</div>
<div class="line">...</div>
<div class="line">InvokeArgument&lt;2&gt;(5, string(<span class="stringliteral">&quot;Hi&quot;</span>), std::ref(foo))</div>
</div><!-- fragment --><p>calls the mock function's #2 argument, passing to it <code>5</code> and <code>string("Hi")</code> by value, and <code>foo</code> by reference.</p>
<h1><a class="anchor" id="autotoc_md247"></a>
Default Action</h1>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft"><a class="el" href="class_action.html">Action</a>   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>DoDefault()</code>   </td><td class="markdownTableBodyLeft">Do the default action (specified by <code>ON_CALL()</code> or the built-in one).   </td></tr>
</table>
<p>{: .callout .note} <b>Note:</b> due to technical reasons, <code>DoDefault()</code> cannot be used inside a composite action - trying to do so will result in a run-time error.</p>
<h1><a class="anchor" id="autotoc_md248"></a>
Composite Actions</h1>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft"><a class="el" href="class_action.html">Action</a>   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>DoAll(a1, a2, ..., an)</code>   </td><td class="markdownTableBodyLeft">Do all actions <code>a1</code> to <code>an</code> and return the result of <code>an</code> in each invocation. The first <code>n - 1</code> sub-actions must return void and will receive a readonly view of the arguments.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>IgnoreResult(a)</code>   </td><td class="markdownTableBodyLeft">Perform action <code>a</code> and ignore its result. <code>a</code> must not return void.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>WithArg&lt;N&gt;(a)</code>   </td><td class="markdownTableBodyLeft">Pass the <code>N</code>-th (0-based) argument of the mock function to action <code>a</code> and perform it.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>WithArgs&lt;N1, N2, ..., Nk&gt;(a)</code>   </td><td class="markdownTableBodyLeft">Pass the selected (0-based) arguments of the mock function to action <code>a</code> and perform it.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>WithoutArgs(a)</code>   </td><td class="markdownTableBodyLeft">Perform action <code>a</code> without any arguments.   </td></tr>
</table>
<h1><a class="anchor" id="autotoc_md249"></a>
Defining Actions</h1>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft">Macro   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ACTION(Sum) { return arg0 + arg1; }</code>   </td><td class="markdownTableBodyLeft">Defines an action <code>Sum()</code> to return the sum of the mock function's argument #0 and #1.    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft"><code>ACTION_P(Plus, n) { return arg0 + n; }</code>   </td><td class="markdownTableBodyLeft">Defines an action <code>Plus(n)</code> to return the sum of the mock function's argument #0 and <code>n</code>.    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft"><code>ACTION_Pk(Foo, p1, ..., pk) { statements; }</code>   </td><td class="markdownTableBodyLeft">Defines a parameterized action <code>Foo(p1, ..., pk)</code> to execute the given <code>statements</code>.   </td></tr>
</table>
<p>The <code>ACTION*</code> macros cannot be used inside a function or class. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.2 </li>
  </ul>
</div>
</body>
</html>
